package sumoTween.demo.swing.animated;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

import sumoTween.Tweener;
import sumoTween.easing.Back;
import sumoTween.easing.Bounce;
import sumoTween.easing.Circ;
import sumoTween.easing.Cubic;
import sumoTween.easing.EasingIF;
import sumoTween.easing.Expo;
import sumoTween.easing.Linear;
import sumoTween.easing.Quad;
import sumoTween.easing.Quart;
import sumoTween.easing.Quint;
import sumoTween.easing.Sine;

public class DemoComponent extends JComponent 
{
	Tweener testTween=new Tweener();
	Font font;
	int currentEasing=0;
	
	public DemoComponent()
	{
		font=new Font("Arial", Font.PLAIN,10);
		init(0);
	}
	
	public EasingIF getEasing() {
		return testTween.getEasing();
	}

	public void nextEasing() {
		init(currentEasing+1);
	}
	
	void init(int easing)
	{
		testTween.clear();
		testTween.setEasing(new Bounce());

		if(easing>9)easing=0;
		
		currentEasing=easing;
		
		if(easing==0)testTween.setEasing(new Linear());
		if(easing==1)testTween.setEasing(new Sine());
		if(easing==2)testTween.setEasing(new Quad());
		if(easing==3)testTween.setEasing(new Cubic());
		if(easing==4)testTween.setEasing(new Expo());
		if(easing==5)testTween.setEasing(new Back());
		if(easing==6)testTween.setEasing(new Bounce());
		if(easing==7)testTween.setEasing(new Quart());
		if(easing==8)testTween.setEasing(new Quint());
		if(easing==9)testTween.setEasing(new Circ());

		
		
		for(int i=0;i<30;i+=2)
		{
			testTween.set(testTween.getTime()+i, 110f, Tweener.EASING_IN);
			testTween.set(testTween.getTime()+i+1, 10f, Tweener.EASING_OUT);
		}

	}
	
	public void paint(Graphics g)
	{
		g.setFont(font);
		g.setColor(new Color(0xffffff));
		g.fillRect(0, 0, getWidth(), getHeight());

		Graphics2D g2d=(Graphics2D)g;
	    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		
		g.setColor(new Color(0xeeeeee));

		g.fillRect(10, 10, 110, 110);
		g.setColor(new Color(0x555555));
		
		g.fillRect(60,testTween.getIntValue(), 10, 10);
	}


}






